void Time0Init(){
    T0TC=0;             //定时器设置为0
    T0PR=1;             //时钟2分频
    T0MCR=0x03;         //设置T0MR0匹配后复位T0TC，产生中断
    T0MR0=Fpclk/2;     //设置1s匹配值
    T0TCR=0x01          //start

    VICIntSelect&=~(0x01<<4);   //定时器0分配为IRQ中断
    VICVectCntl0=0x20|4;        //分配为IRQ通道0
    VICVectAddr0=(uint32)Timer0_ISR;
    VICIntEnable=(1<<4);        //中断使能
}

void Time0Init(){
    T0TC=0;             //定时器设置为0
    T0PR=0;             //时钟2分频
    T0MCR=0x02;         //设置T0MR0匹配后复位T0TC，产生中断
    T0EMR=0x30;         //T0MR0匹配后MAT0.0输出翻转
    T0MR0=Fpclk*2;      //设置2s匹配
    T0TCR=0x01;         //start
}

void Measure(){
    T0TC=0;
    T0PR=0;
    while((IO0PIN&0x01)!=0);    //等待p0.0端口变为低电平
    T0TCR=0x01;
    while((IO0PIN&0x01)==0);    //等待p0.0端口恢复高电平
    T0TCR=0x00;
    time=T0TC/Fpclk;            //得到低电平脉冲的时间宽度
}